#include <iostream>

using namespace std;

bool hasPrefix(string src, string prefix)
{
    auto const pos = src.find(prefix);
    
    if (pos != string::npos && pos == 0) {
        return true;
    }
    
    return false;
}

bool hasSuffix(string src, string suffix)
{
    auto const pos = src.find_last_of(suffix);
    
    if (pos != string::npos && pos == (src.length() - 1)) {
        return true;
    }
    
    return false;
}

int main() {
    string str1 = "as/dp";
    string str2 = "/as/dp";
    string str3 = "as/dp/";
    string str4 = "/as/dp/";
    
    string::size_type index = str1.find_last_of("/");
    
    cout << "str1.length " << str1.length() << " index: " << index << endl;
    
    cout << endl;
    
    cout << str1 << " 包含前缀'/': " << hasPrefix(str1, "/") << endl;
    cout << str1 << " 包含后缀'/': " << hasSuffix(str1, "/") << endl;
    
    cout << str2 << " 包含前缀'/': " << hasPrefix(str2, "/") << endl;
    cout << str2 << " 包含后缀'/': " << hasSuffix(str2, "/") << endl;
    
    cout << str3 << " 包含前缀'/': " << hasPrefix(str3, "/") << endl;
    cout << str3 << " 包含后缀'/': " << hasSuffix(str3, "/") << endl;
    
    cout << str4 << " 包含前缀'/': " << hasPrefix(str4, "/") << endl;
    cout << str4 << " 包含后缀'/': " << hasSuffix(str4, "/") << endl;
    
    return 0;
}
